const path = require("path")

const nodeExternals = require("webpack-node-externals")

module.exports = {
  mode: "development",
  target: 'node',
  entry: './src/server/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'build')
  },
  externals: [nodeExternals()],
  resolve: {
    extensions: [".js", ".jsx", ".json", ".ts", ".tsx"]
  },
  module: {
    rules: [
      {
        test: /\.js(x?)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [['@babel/preset-env', {
              useBuiltIns: "usage",
              corejs: 3
            }], "@babel/preset-react"],
          }
        }
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        // style-loader 会向 window 中挂载，在 server 端渲染会出现问题，
        use: ["isomorphic-style-loader", {
          loader: "css-loader",
          options: {
            modules: {
              localIdentName: "[name]_local_[hash:base64:5]"
            },
            importLoaders: 1
          }
        }]
      }
    ]
  },
  watch: true
}